//#include <iostream>
//#include <istream>
//#include <ostream>
//#include <string>
//#include <boost/asio.hpp>
//#include <boost/bind.hpp>
//
//using namespace boost::asio;
//using boost::asio::ip::tcp;
//using boost::bind;
//
//class client
//{
//public:
//	client( boost::asio::io_service & io_service, std::string const & host, std::string const & path)
//		: resolver_(io_service), socket_(io_service)
//	{
//		//std::ostream request_stream(&request_);
//		//request_stream << "GET " << path << " HTTP/1.0\r\n";
//		//request_stream << "Host: " << host << "\r\n";
//		//request_stream << "Accept: */*\r\n";
//		//request_stream << "Connection: close\r\n\r\n";
//
//		//tcp::resolver::query query(host, "http");
//
//		//resolver_.async_resolve(query,
//		//					bind(&client::handle_resolve, this, placeholders::error, placeholders::iterator)
//		//					);
//
//
//		//http://www.codeproject.com/KB/IP/akashhttpproxy.aspx
//		//http://www.innovation.ch/personal/ronald/ntlm.html
//
//		//CONNECT www3.discovirtual.com.ar:443 HTTP/1.0
//
//		std::ostream request_stream(&request_);
//
//		//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//
//		//request_stream << "GET " << path << " HTTP/1.0\r\n";
//		//request_stream << "Host: " << host << "\r\n";
//		//request_stream << "Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S\r\n";			//TODO:
//		//request_stream << "\r\n";
//
//		//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//
////
////Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
////Accept-Language: es-AR
////User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
////Accept-Encoding: gzip, deflate
////Proxy-Connection: Keep-Alive
////Host: www.google.com
////Cookie: PREF=ID=95f129ae48a27026:U=f417ab71a4b80412:FF=0:TM=1313506129:LM=1313590779:S=MqTcUdUawVWmf4Hl; NID=51=lwbE_jekFZ13HvMAtxyibXG16M7uukjbi5w7sOOoHcL4WiQL-lSulpnYJQtSF58SOZvFrZPL4r7FSP1IXAPB75UoWCg23YpJ8hp45toWsUeYAx0Tpb-TNJf4Mkwkcscm
//
//
//		request_stream << "GET " << "http://www.google.com.ar/" << " HTTP/1.1" << "\r\n";
//		//request_stream << "Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S\r\n";			//TODO:
//		request_stream << "Proxy-Connection: Keep-Alive" << "\r\n";
//		request_stream << "Host: " << host << "\r\n";
//		request_stream << "\r\n";
//
//
//		//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//
//
////GET http://www.google.com/search?hl=es&q=123&lr= HTTP/1.1
////Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
////Accept-Language: es-AR
////User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
////Accept-Encoding: gzip, deflate
////Proxy-Connection: Keep-Alive
////Cookie: PREF=ID=95f129ae48a27026:U=f417ab71a4b80412:FF=0:TM=1313506129:LM=1313590779:S=MqTcUdUawVWmf4Hl; NID=51=lwbE_jekFZ13HvMAtxyibXG16M7uukjbi5w7sOOoHcL4WiQL-lSulpnYJQtSF58SOZvFrZPL4r7FSP1IXAPB75UoWCg23YpJ8hp45toWsUeYAx0Tpb-TNJf4Mkwkcscm
////Proxy-Authorization: Negotiate TlRMTVNTUAABAAAAl7II4gYABgAzAAAACwALACgAAAAGAbEdAAAAD1BST0ctRlJBLTMxQ0RTLUJB
////Host: www.google.com
//
//		request_stream << "GET " << "http://www.google.com.ar/" << " HTTP/1.1" << "\r\n";
//		//request_stream << "Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S\r\n";			//TODO:
//		request_stream << "Proxy-Connection: Keep-Alive" << "\r\n";
//		request_stream << "Proxy-Authorization: Negotiate TlRMTVNTUAABAAAAl7II4gYABgAzAAAACwALACgAAAAGAbEdAAAAD1BST0ctRlJBLTMxQ0RTLUJB" << "\r\n";
//		request_stream << "Host: " << host << "\r\n";
//		request_stream << "\r\n";
//
//
//				//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//
//
//
////GET http://www.google.com/search?hl=es&q=123&lr= HTTP/1.1
////Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
////Accept-Language: es-AR
////User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
////Accept-Encoding: gzip, deflate
////Proxy-Connection: Keep-Alive
////Cookie: PREF=ID=95f129ae48a27026:U=f417ab71a4b80412:FF=0:TM=1313506129:LM=1313590779:S=MqTcUdUawVWmf4Hl; NID=51=lwbE_jekFZ13HvMAtxyibXG16M7uukjbi5w7sOOoHcL4WiQL-lSulpnYJQtSF58SOZvFrZPL4r7FSP1IXAPB75UoWCg23YpJ8hp45toWsUeYAx0Tpb-TNJf4Mkwkcscm
////Host: www.google.com
////Proxy-Authorization: Negotiate TlRMTVNTUAADAAAAGAAYAKIAAAA+AT4BugAAAAwADABYAAAAKAAoAGQAAAAWABYAjAAAABAAEAD4AQAAFYKI4gYBsR0AAAAPy72xJaOjXE2Rr5LIM+1luUMARABTAC0AQgBBAEYAZQByAG4AYQBuAGQAbwAuAFAAZQBsAGwAaQBjAGMAaQBvAG4AaQBQAFIATwBHAC0ARgBSAEEALQAzADEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKRmooE1Q3W7tOvV84UALuQEBAAAAAAAAF3tYjtyBzAG104wK5Ak3vQAAAAACAAwAQwBEAFMALQBCAEEAAQAQAFcAQQBSAEcAVABZADAAMQAEABgAYwBkAHMALQBiAGEALgBsAG8AYwBhAGwAAwAqAFcAQQBSAEcAVABZADAAMQAuAGMAZABzAC0AYgBhAC4AbABvAGMAYQBsAAUAGABjAGQAcwAtAGIAYQAuAGwAbwBjAGEAbAAHAAgAF3tYjtyBzAEGAAQAAgAAAAgAMAAwAAAAAAAAAAAAAAAAMAAAMuDHhWGrtMlumrjuhPLFjWz3nL//clg/Ac3TAlb47hkKABAAAAAAAAAAAAAAAAAAAAAAAAkAHABIAFQAVABQAC8AMQAyADcALgAwAC4AMAAuADEAAAAAAAAAAAAAAAAAtEBJtuOZ/iNIPu1YYzoorQ==
//
//				//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//
//
//
//		tcp::endpoint endpoint( boost::asio::ip::address::from_string("10.147.64.2"), 8080);
//
//		socket_.async_connect(endpoint,
//			bind(&client::handle_connect, this, placeholders::error));
//
//	}
//
//private:
//	void handle_resolve(const boost::system::error_code& err, tcp::resolver::iterator endpoint_iterator)
//	{
//		if (!err)
//		{
//			boost::asio::async_connect(socket_, endpoint_iterator,
//					bind(&client::handle_connect, this, placeholders::error));
//		}
//		else
//		{
//			std::cout << "Error: " << err.message() << "\n";
//		}
//	}
//
//	void handle_connect(const boost::system::error_code& err)
//	{
//		if (!err)
//		{
//			// The connection was successful. Send the request.
//			boost::asio::async_write(socket_, request_,
//					bind(&client::handle_write_request, this, placeholders::error)
//					);
//		}
//		else
//		{
//			std::cout << "Error: " << err.message() << "\n";
//		}
//	}
//
//	void handle_write_request(const boost::system::error_code& err)
//	{
//		if (!err)
//		{
//			// Read the response status line. The response_ streambuf will
//			// automatically grow to accommodate the entire line. The growth may be
//			// limited by passing a maximum size to the streambuf constructor.
//			boost::asio::async_read_until(socket_, response_, "\r\n",
//					bind(&client::handle_read_status_line, this, placeholders::error)
//					);
//		}
//		else
//		{
//			std::cout << "Error: " << err.message() << "\n";
//		}
//	}
//
//	void handle_read_status_line(const boost::system::error_code& err)
//	{
//		if (!err)
//		{
//			// Check that response is OK.
//			std::istream response_stream(&response_);
//			std::string http_version;
//			response_stream >> http_version;
//			unsigned int status_code;
//			response_stream >> status_code;
//			std::string status_message;
//			std::getline(response_stream, status_message);
//			
//			if (!response_stream || http_version.substr(0, 5) != "HTTP/")
//			{
//				std::cout << "Invalid response\n";
//				return;
//			}
//
//			if (status_code != 200)
//			{
//				std::cout << "Response returned with status code ";
//				std::cout << status_code << "\n";
//				return;
//			}
//
//			// Read the response headers, which are terminated by a blank line.
//			boost::asio::async_read_until(socket_, response_, "\r\n\r\n",
//					bind(&client::handle_read_headers, this, placeholders::error)
//					);
//		}
//		else
//		{
//			std::cout << "Error: " << err << "\n";
//		}
//	}
//
//	void handle_read_headers(const boost::system::error_code& err)
//	{
//		if (!err)
//		{
//			// Process the response headers.
//			std::istream response_stream(&response_);
//			std::string header;
//
//			while (std::getline(response_stream, header) && header != "\r")
//			{
//				std::cout << header << "\n";
//			}
//			
//			std::cout << "\n";
//
//			// Write whatever content we already have to output.
//			if (response_.size() > 0)
//			{
//				std::cout << &response_;
//			}
//
//			// Start reading remaining data until EOF.
//			boost::asio::async_read(socket_, response_,
//					boost::asio::transfer_at_least(1),
//					bind(&client::handle_read_content, this, placeholders::error)
//					);
//		}
//		else
//		{
//			std::cout << "Error: " << err << "\n";
//		}
//	}
//
//	void handle_read_content(const boost::system::error_code& err)
//	{
//		if (!err)
//		{
//			// Write all of the data that has been read so far.
//			std::cout << &response_;
//
//			// Continue reading remaining data until EOF.
//			boost::asio::async_read(socket_, response_,
//					boost::asio::transfer_at_least(1),
//					bind(&client::handle_read_content, this, placeholders::error)
//					);
//		}
//		else if (err != boost::asio::error::eof)
//		{
//			std::cout << "Error: " << err << "\n";
//		}
//	}
//
//	tcp::resolver resolver_;
//	tcp::socket socket_;
//	boost::asio::streambuf request_;
//	boost::asio::streambuf response_;
//};
//
//int main(int argc, char* argv[])
//{
//	try
//	{
//		//if (argc != 3)
//		//{
//		//	std::cout << "Usage: async_client <host> <path>\n";
//		//	std::cout << "Example:\n";
//		//	std::cout << "  async_client www.boost.org /LICENSE_1_0.txt\n";
//		//	return 1;
//		//}
//
//		//std::string host( argv[1] );
//		//std::string path( argv[2] );
//
//		//std::string host( "www.google.com.ar" );
//		//std::string path( "/" );
//
//		std::string host( "www.google.com.ar" );
//		//port : 8080
//		std::string path( "/" );
//
//
//		boost::asio::io_service io_service;
//		client c(io_service, host, path);
//		io_service.run();
//	}
//	catch (std::exception& e)
//	{
//		std::cout << "Exception: " << e.what() << "\n";
//	}
//
//	return 0;
//}
